<template>
  <div class="index">
    <el-menu
      :default-active="$route.path"
      class="el-menu-vertical-demo"
      :collapse="collapse"
      background-color="#545c64"
      text-color="#ccc"
      active-text-color="#fff"
      :router="true"
      id="er-back"
    >
      <template v-for="item of routes">
        <el-submenu
          :key="item.path"
          v-if="item.children && item.children.length > 1"
          :index="item.path"
        >
          <template #title>
            <i :class="item.meta.icon"></i>
            <span>{{ item.meta.name }}</span>
          </template>
          <template v-for="im of item.children.slice(1)">
            <el-menu-item :key="im.path" :index="im.path">
              <i :class="im.meta.icon"></i>
              <span>{{ im.meta.name }}</span>
            </el-menu-item>
          </template>
        </el-submenu>
        <el-menu-item :key="item.path" v-else :index="item.path">
          <i :class="item.meta.icon"></i>
          <span>{{ item.meta.name }}</span>
        </el-menu-item>
      </template>
    </el-menu>
  </div>
</template>

<script>
// import { mapState } from "vuex";

export default {
  props: {
    collapse: Boolean
  },
  computed: {
    routes() {
      return this.$store.state.promission.routes
    }
  }
};
</script>

<style lang="sass">
.index,
.el-menu
  height: 100%
#er-back
  .el-submenu
    .el-menu
      .el-menu-item
        background: #50585f
</style>